﻿window.onload = function () {
    swal({
        title: "说明!",
        text: "由于是连续运动，所以在计算扭矩时只需考虑负载牛矩，启动扭矩忽略，但必须考虑到惯量的匹配!!!",
        icon: "success",
    });
}
/*左边 全局变量*/
let pi = 3.1416;
let g = 9.8;
let leftBtn = document.querySelector("#dianjiSpeed").querySelector("button");
let leftIpt = document.querySelector("#dianjiSpeed").querySelectorAll("input");
////
let centerIpt = document.querySelector("#zhongjian1").querySelectorAll("input");
////
let rightBtn = document.querySelector("#fuzai").querySelector("button");
let rightIpt = document.querySelector("#fuzai").querySelectorAll("input");
let D = "";
let i = "";
let ηG = "";
///电机转速
let N ;/////减速机输出轴转速
window.addEventListener("load", function () {
    leftBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(leftIpt[0].value == "" || leftIpt[1].value == "" || leftIpt[2].value == "")) {
        leftBtn.disabled = false;
    }
    else {
        leftBtn.disabled = true;
    }
})
leftBtn.addEventListener("click", function () {
    D = parseFloat(leftIpt[1].value)
    i = parseFloat(leftIpt[2].value)
    N = parseFloat(leftIpt[0].value)/(pi*D)
    leftIpt[3].value = N * i;
    ///中间值显示
    centerIpt[0].value = D;
    centerIpt[1].value = N;
    rightCenterIpt[0].value = D;
    rightCenterIpt[1].value =N;
})
/////负载转矩Tlm
let F;///减速机轴向负载
let TL////减速机轴负载转矩
let mL = ""///皮带与工作物总质量
let m2////滚筒质量
let Tlm = ""////负载转矩
window.addEventListener("load", function () {
    rightBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightIpt[0].value == "" || rightIpt[1].value == "" || rightIpt[2].value == "" || rightIpt[3].value == "" || rightIpt[4].value == "" || rightIpt[5].value == "")) {
        rightBtn.disabled = false;
    }
    else {
        rightBtn.disabled = true;
    }
})
rightBtn.addEventListener("click", function () {
    if (D == "" || i == "") {
        swal("请先输入滚筒直径、减速比i的值");
        rightIpt[6].value = "";
        return;

    }
    mL = rightIpt[1].value;
    ηG = rightIpt[5].value;
    F = parseFloat(rightIpt[0].value) + mL * g *
        ((Math.sin(parseFloat(rightIpt[2].value) * pi / 180)) + parseFloat(rightIpt[3].value) * (Math.cos(parseFloat(rightIpt[2].value) * pi / 180)))
    TL = F * D / (2 * parseFloat(rightIpt[4].value));
    rightIpt[6].value = TL / (i * parseFloat(rightIpt[5].value))
    Tlm = parseFloat(rightIpt[6].value)
    ////高亮显示
    let f = document.querySelector("#f");
    let tl = document.querySelector("#tl");
    f.style.color = "red";
    tl.style.color = "red";
    /////中间值显示
    centerIpt[2].value = F;
    centerIpt[3].value = TL;
    rightCenterIpt[4].value = Tlm;
})
/////右边全局变量
let rightLeftIpt = document.querySelector("#dianjizhou").querySelectorAll("input");
let rightLeftBtn = document.querySelector("#dianjizhou").querySelector("button");
////right center
let rightCenterIpt = document.querySelector("#zhongjian2").querySelectorAll("input");
///right left 
let rightRightBtn = document.querySelector("#bixuzhuanju").querySelector("button");
let rightRightIpt = document.querySelector("#bixuzhuanju").querySelectorAll("input");
let rightRightIpt2 = document.querySelector("#guanliangbi").querySelectorAll("input");

///电机轴加速转矩Ts
window.addEventListener("load", function () {
    rightLeftBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightLeftIpt[0].value == "" || rightLeftIpt[1].value == "")) {
        rightLeftBtn.disabled = false;
    }
    else {
        rightLeftBtn.disabled = true;
    }
})
let Jm1;////皮带和工作物的惯量
let Jm2;///滚动的惯量
let JL;////折算到减速机轴的负载惯量
let Jm;///电机惯量
rightLeftIpt[0].addEventListener("input", function () {
    if (D == "" || mL == "" ) {
        swal("请先输入滚筒直径D的值  or 皮带与工作物的总质量mL")
        rightLeftIpt[0].value = "";
        return;
    }
})
rightLeftBtn.addEventListener("click", function () {
    Jm = rightLeftIpt[1].value
    Jm1 = mL * Math.pow((D / 2), 2);
    Jm2 = 1 / 8 * parseFloat(rightLeftIpt[0].value) * Math.pow(D, 2);
    JL = Jm1 + 2 * Jm2;
    rightLeftIpt[2].value = JL
    ////高亮显示
    let jm1 = document.querySelector("#jm1");
    let jm2 = document.querySelector("#jm2");
    jm1.style.color = "red";
    jm2.style.color = "red";
    rightCenterIpt[2].value = Jm1;
    rightCenterIpt[3].value = Jm2;
    ////惯量比
    rightRightIpt2[0].value = (JL / (i * i)) / Jm
})

///center2
////必须转矩
window.addEventListener("load", function () {
    rightRightBtn.disabled = true;
})

window.addEventListener('input', function () {
    if (!(rightRightIpt[0].value == "")) {
        rightRightBtn.disabled = false;
    }
    else {
        rightRightBtn.disabled = true;
    }
})
rightRightIpt[0].addEventListener("input", function () {
    if (Tlm == "") {
        swal("请先计算负载转矩Tlm的值")
        rightRightIpt[0].value = "";
        return;
    }
})
rightRightBtn.addEventListener("click", function () {
    rightRightIpt[1].value = Tlm  * parseFloat(rightRightIpt[0].value)

})
//////负荷与电机惯量比



























